<template>
    <div>
        <a-card title="BUC">
            <a-button slot="extra" type='primary' style="margin-right: 10px;" @click="handleFormat">重置</a-button>
            <a-button slot="extra" type='primary' @click="handleSet">设置</a-button>
            <a-form-model :model="formBUC" :label-col="labelCol" :wrapper-col="wrapperCol">
                <a-row>
                    <a-col :span=24>
                        <a-form-model-item label="频率设置(GHz)">
                            <a-input-number style="width:100%" :step="0.0001" :precision="4" :min=30
                                v-model="formBUC.frequency"></a-input-number>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span=24>
                        <a-form-model-item label="衰减器设置(dB)">
                            <a-input-number :min=0 :max=31 style="width:100%" v-model="formBUC.attenuator"
                                placeholder="0-31dB"></a-input-number>

                        </a-form-model-item>
                    </a-col>
                </a-row>


            </a-form-model>
        </a-card>
    </div>


</template>

<script>
import { httpAction } from '../../../api/manage'
export default {
    data() {
        return {
            formBUC: {
                // frequency
            },
            labelCol: { span: 10 },
            wrapperCol: { span: 12 },
            url: {
                sendDevicePackage: '/device/nmcDeviceGridValue/sendDevicePackage'
            }
        }
    },
    created() {
        console.log()
    },
    methods: {
        handleFormat() {
            this.formBUC = {}
        },
        formatFrequency(val) {
            // 0x000000代表频率为30000000KHz,0x000001代表频率为30 000 100KHz,步进100KHz
            // 30.56GHz  


        },
        handleSet() {
            let data = {
                "channelCode": "BUC",
                "gridValues": [
                    {
                        "gridCode": "BUC-控制-频率",
                        "gridValue": Number(((this.formBUC.frequency * 1000000) - 30000000) / 100).toString(16)
                    },
                    {
                        "gridCode": "BUC-控制-衰减器",
                        "gridValue": Number(this.formBUC.attenuator).toString(16)
                    }
                ],
                "packageCode": "BUC-控制"
            }
            httpAction(this.url.sendDevicePackage, data, 'post').then(res => {
                if (res.success) {
                    this.$message.success(res.message)
                } else {
                    this.$message.error(res.message)
                }
            })
        },
    }
}
</script>

<style scoped>
.ant-card-bordered {
    height: 330px;
    overflow-y: auto;
}
</style>